package com.zzptc.zzsgz.bdsjws.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.utils.DanceWageTimer;
import com.zzptc.zzsgz.bdsjws.views.RatingBar;
import com.zzptc.zzsgz.bdsjws.views.RatingView;

import java.util.Random;

import butterknife.BindView;
import butterknife.OnClick;

public class MainActivity extends BaseActivity {


    @BindView(R.id.rating_view)
    RatingView ratingView;
    @BindView(R.id.tv_num)
    TextView tv_Num;
    int one = new Random().nextInt(10) + 1;
    int two = new Random().nextInt(10) + 1;
    int three = new Random().nextInt(10) + 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //发送
        Intent intent = new Intent();
        intent.setAction("updateVersion");
        sendBroadcast(intent);


    }

    @Override
    public int getContentXML() {
        return R.layout.activity_main;
    }

    @Override
    public void initData() {


    }

    @Override
    public void initView() {
//根据产生的随机数one来定 （>=8）高、(<=5)低、(8>one>5)中    三元运算符  表达式? 结果一 :结果二
        ratingView.addRatingBar(new RatingBar(one, one >= 8 ? "清晰度高" : (one <= 5) ? "清晰度低" : "清晰度中"));
        ratingView.addRatingBar(new RatingBar(two, two >= 8 ? "流畅度高" : (two <= 5) ? "流畅度低" : "流畅度中"));
        ratingView.addRatingBar(new RatingBar(three, three >= 8 ? "安全度高" : (three <= 5) ? "安全度低" : "安全度中"));
        ratingView.show();
        ratingView.setAnimatorListener(new RatingView.AnimatorListener() {
            @Override
            public void onRotateStart() {

            }

            @Override
            public void onRotateEnd() {
                //跳数效果
                int num = (int) ((one * 0.5 + two * 0.3 + three * 0.2) * 10);
                // tv_Num.setText(num+"");
                long totalExecuteTime = DanceWageTimer.getTotalExecuteTime(num, 20);
                DanceWageTimer danceWageTimer = new DanceWageTimer(totalExecuteTime, 20, tv_Num, num);
                danceWageTimer.start();

            }

            @Override
            public void onRatingStart() {

            }

            @Override
            public void onRatingEnd() {

            }
        });
        //tv_Num.setText((one*0.5+two*0.3+three*0.2));


    }

    @OnClick(R.id.iduser)
    public void skipUserActivity(View view) {
        // Toast.makeText(this, "======", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(this, UserActivity.class));
    }

    @OnClick(R.id.tv_bbx)
    public void onViewClicked() {
        startActivity(new Intent(this,BBXActivity.class));

        //Intent intent=new Intent();
       // intent.setClass(this,BBXActivity.class);
       // startActivity(intent);

    }
}
